<template>
    <div class="app-container">
        <div>
            <h3>会员注册设置</h3>
        </div>
        <div class="setting-item">
            <div class="item_title">
                直接上线
            </div>
            <div class="item_value">
                佣金：<el-input-number :min="0.00" :step="0.01" v-model="superiorV1Commision.settingValue" @change="handleChangeSettingValue('1')"></el-input-number>元
            </div>
            <div class="item_value">
                积分：<el-input-number :min="0" :step="1" v-model="superiorV1Integral.settingValue" @change="handleChangeSettingValue('2')"></el-input-number>
            </div>
        </div>
        <div class="setting-item">
            <div class="item_title">
                间接上线
            </div>
            <div class="item_value">
                佣金：<el-input-number :min="0.00" :step="0.01" v-model="superiorV2Commision.settingValue" @change="handleChangeSettingValue('3')"></el-input-number>元
            </div>
            <div class="item_value">
                积分：<el-input-number :min="0" :step="1" v-model="superiorV2Integral.settingValue" @change="handleChangeSettingValue('4')"></el-input-number>
            </div>

        </div>


    </div>
</template>

<script>
    import {getAllSetting,saveOrUpdateSetting} from '@/api/systemSetting'
  export default {
    name: 'setting',
    data(){
      return {
        superiorV1Commision:{settingTypeId:'SUPERIOR_V1_COMMISION',settingValue:0},
        superiorV1Integral:{settingTypeId:'SUPERIOR_V1_INTEGRAL',settingValue:0},
        superiorV2Commision:{settingTypeId:'SUPERIOR_V2_COMMISION',settingValue:0},
        superiorV2Integral:{settingTypeId:'SUPERIOR_V2_INTEGRAL',settingValue:0},
      }
    },
    created(){
      getAllSetting().then(response=>{
        let systemSettings = response.result;
        if(systemSettings && systemSettings.length>0){
          systemSettings.forEach(item=>{
            if(item.settingTypeId==='SUPERIOR_V1_COMMISION'){
              this.superiorV1Commision = item;
            }
            if(item.settingTypeId==='SUPERIOR_V1_INTEGRAL'){
              this.superiorV1Integral = item;
            }
            if(item.settingTypeId==='SUPERIOR_V2_COMMISION'){
              this.superiorV2Commision = item;
            }
            if(item.settingTypeId==='SUPERIOR_V2_INTEGRAL'){
              this.superiorV2Integral = item;
            }
          })
        }
      })
    },
    methods:{
      handleChangeSettingValue(key){
        if(key==='1'){
          saveOrUpdateSetting(this.superiorV1Commision);
        }
        if(key==='2'){
          saveOrUpdateSetting(this.superiorV1Integral);
        }
        if(key==='3'){
          saveOrUpdateSetting(this.superiorV2Commision);
        }
        if(key==='4'){
          saveOrUpdateSetting(this.superiorV2Integral);
        }
      }
    }
  }
</script>

<style scoped>
    .setting-item{
        display: flex;
        height: 60px;
    }
    .item_title{
        height: 60px;
        font-size: 18px;
        font-weight: bold;
        display: flex;
        width: 100px;
        align-items: center;
        justify-content: flex-end;
    }
    .item_value{
        height: 60px;
        display: flex;
        width: 200px;
        margin-left: 20px;
        align-items: center;
    }
    .item_value_input{
        width: 120px;
    }

</style>
